import React from 'react';

import BookOpenImage from '@/assets/images/auth/Convert.png';
import { ModalContext } from '@/shared/context/ModalContext';
import { Modal } from '@/shared/ui';
import Image from 'next/image';
import { useRouter } from 'next/router';

import cs from './MessageSendModal.module.scss';

export const MessageSendModal = () => {
  const { closeModal, data, setData } = React.useContext(ModalContext);
  const router = useRouter();
  const handleClose = () => {
    closeModal();
    setData(() => {});
    if (data?.url) {
      router.push(data.url);
    } else {
      router.reload();
    }
  };
  return (
    <Modal className={cs.modal} isOpen onCloseClick={() => handleClose()}>
      <div className={cs.container}>
        <div className={cs.image}>
          <Image alt="icon" draggable="false" fill src={BookOpenImage} />
        </div>

        <div className={cs.text}>
          <div className={cs.title_container}>
            <h1 className={cs.title}>Сообщение отправлено</h1>
            <p className={cs.info}>{data?.courseName}</p>
          </div>
          <p className={cs.description}>
            Ответим на почту {data.email}. <br />
            Проверяйте Входящие или Спам.
          </p>
        </div>
      </div>
    </Modal>
  );
};
